#!/bin/bash

NAME="financial_daily"
NUM_WORKERS=5
DJANGO_WSGI_MODULE=financial_daily.wsgi

# Host IP
HOST_IP=$(host `hostname` | awk '/^[[:alnum:].-]+ has address/ { print $4 }')
PORT=8000

echo "Starting $NAME as `whoami` on $HOST_IP $PORT"

# Virtual env
export WORKON_HOME=$HOME/.virtualenvs
source `which virtualenvwrapper.sh`
workon $FINANCIAL_DAILY_VIRTUAL_ENV_NAME

# Start Django Gunicorn
# Programs meant to be run under supervisor should not daemonize themselves (do not use --daemon)
exec gunicorn ${DJANGO_WSGI_MODULE}:application \
    --name $NAME \
    --bind $HOST_IP:$PORT \
    --workers $NUM_WORKERS \
    --log-level=debug \
